package del1;

/*
 * This is the class TrafficLight for Assignment 7.1
 */

public class TrafficLight {

	private SignalColor signal = SignalColor.GREEN;

	public boolean drivingAllowed() {
		return signal.drivingAllowed();
	}

	public void setSignalColor(SignalColor color) {
		signal = color;
	}

	/*
	 * @return the color of the TrafficLight with lower case letters.
	 */
	public String getColorOfLight() {
		return signal.toString().toLowerCase();
	}

	/*
	 * This toString method prints out the color of the TrafficLight and tells
	 * us whether or not driving is allowed.
	 */
	@Override
	public String toString() {
		if (signal == SignalColor.RED) {
			return "The light is " + getColorOfLight()
					+ ". Driving is not allowed!";
		} else {
			return "The light is " + getColorOfLight()
					+ ". Driving is allowed!";
		}
	}

	/*
	 * We've added another print statement, to get all cases printed.
	 */
	public static void main(String[] args) {
		TrafficLight trafficlight = new TrafficLight();		// Creates a new TrafficLight

		System.out.println(trafficlight);					// Should print "The light is green. Driving is allowed!"

		trafficlight.setSignalColor(SignalColor.YELLOW);	
		System.out.println(trafficlight);					// Should print "The light is yellow. Driving is allowed!"
		
		trafficlight.setSignalColor(SignalColor.RED);		
		System.out.println(trafficlight);					// Should print "The light is red. Driving is not allowed!"
	}
}
